package com.xwq.commodityitemsproductservice.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xwq.api.IProductService;
import com.xwq.commons.base.BaseServiceImpl;
import com.xwq.commons.base.IBaseDao;
import com.xwq.entity.TProduct;
import com.xwq.entity.TProductDesc;
import com.xwq.mapper.TProductDescMapper;
import com.xwq.mapper.TProductMapper;
import com.xwq.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class ProductServiceImpl extends BaseServiceImpl<TProduct> implements IProductService {
    @Autowired
   private TProductMapper productMapper;
    @Autowired
    private TProductDescMapper productDescMapper;
    @Override
    public IBaseDao getBaseDao() {
        return productMapper;
    }

    @Override
    @Transactional
    public Long add(ProductVO productVO) {
        //1.添加商品的基本信息
        productMapper.insertSelective(productVO.getProduct());
        //2.添加商品的描述信息
        TProductDesc productDesc = new TProductDesc();
        productDesc.setProductId(productVO.getProduct().getId());
        productDesc.setProductDesc(productVO.getProductDesc());
        productDescMapper.insertSelective(productDesc); //有判断是否为null的
        return productVO.getProduct().getId();  //返回主键id
    }
}
